package com.ymatou.iapi.comments.testcase;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.comments.parameter.AddProductCommentAsyncBean;
import com.ymatou.iapi.comments.service.AddProductCommentAsyncCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;

@TestSuite
public class Ts_AddProductCommentAsync   {
	
    private static AddProductCommentAsyncBean addcomment1;
    private static AddProductCommentAsyncCall addcomment;
    

    @BeforeClass
    public static void setUp() {
        Logger.createResultFile("添加商品评论");
    }

    @Before
    public void caseUp() {
    	addcomment1 = new AddProductCommentAsyncBean();
    	addcomment = new AddProductCommentAsyncCall();
        
    }

    @AfterClass
    public static void tearDown() {
        Logger.generateResult(addcomment.getOpurl());
    }

    @After
    public void caseDown() {
        Logger.end();
    }
    
	@Test
	@Category({P1.class})
	@TestCase
    public void Tc_AddProductCommentAsync_001(){
    	
    	try {
    	Logger.start(true,"正常评论商品");
    	addcomment1.setAppType(1);
    	addcomment1.setUserId(4085);
    	addcomment1.setUserType(0);
    	addcomment1.setUserName("lunchzhao");
    	addcomment1.setUserLogo("http://p6.img.ymatou.com/G01/M00/29/DA/rBBlD1eh1UOAX65nAAAnAOLte-s859_o.jpg");
    	addcomment1.setSourceId("d39ca580-3581-4458-8fd2-21eb43c45fe0");
    	addcomment1.setSourceType(1);
    	addcomment1.setSourceImageUrl(null);
    	addcomment1.setProductDescription(null);
    	addcomment1.setFreeShopping(7);
    	addcomment1.setFreeTax(8);
    	addcomment1.setProductEndTime(null);
    	addcomment1.setToUserId(3383);
    	addcomment1.setToUserName("wesper");
    	addcomment1.setToUserType(1);
    	addcomment1.setCommentContent("dwtest");
    	addcomment1.setIPAddress("172.16.21.84");
    	addcomment1.setIsAnonymous(true);
    	
    	addcomment.setData(addcomment1);
    	addcomment.callService();
    	
		Logger.comment("验证返回值");
		Logger.verifyEquals(200,new JSONObject(addcomment.getReturnData()).getInt("Status"), "响应报文-返回码");
    	
    	
    	
    	
	   }
	     catch(Exception e){
		   Logger.fail(e);
	   }
    	
        
    }
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProductCommentAsync_002(){
		
		try {
    	Logger.start(true,"评论商品id为空，评论失败");
    	addcomment1.setAppType(1);
    	addcomment1.setUserId(4085);
    	addcomment1.setUserType(0);
    	addcomment1.setUserName("lunchzhao");
    	addcomment1.setUserLogo("http://p6.img.ymatou.com/G01/M00/29/DA/rBBlD1eh1UOAX65nAAAnAOLte-s859_o.jpg");
    	addcomment1.setSourceId(null);
    	addcomment1.setSourceType(1);
    	addcomment1.setSourceImageUrl(null);
    	addcomment1.setProductDescription(null);
    	addcomment1.setFreeShopping(7);
    	addcomment1.setFreeTax(8);
    	addcomment1.setProductEndTime(null);
    	addcomment1.setToUserId(3383);
    	addcomment1.setToUserName("wesper");
    	addcomment1.setToUserType(1);
    	addcomment1.setCommentContent("dwtest");
    	addcomment1.setIPAddress("172.16.21.84");
    	addcomment1.setIsAnonymous(true);
    	
    	addcomment.setData(addcomment1);
    	
		addcomment.callService();
			Logger.comment("验证返回值");
			Logger.verifyEquals(500,new JSONObject(addcomment.getReturnData()).getInt("Status"), "响应报文-返回码");
		} catch(Exception e){
			   Logger.fail(e);
		   }
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_AddProductCommentAsync_003(){
		
		
		try {
    	Logger.start(true,"评论商品id不存在，评论失败");
    	addcomment1.setAppType(1);
    	addcomment1.setUserId(4085);
    	addcomment1.setUserType(0);
    	addcomment1.setUserName("lunchzhao");
    	addcomment1.setUserLogo("http://p6.img.ymatou.com/G01/M00/29/DA/rBBlD1eh1UOAX65nAAAnAOLte-s859_o.jpg");
    	addcomment1.setSourceId("23424");
    	addcomment1.setSourceType(1);
    	addcomment1.setSourceImageUrl(null);
    	addcomment1.setProductDescription(null);
    	addcomment1.setFreeShopping(7);
    	addcomment1.setFreeTax(8);
    	addcomment1.setProductEndTime(null);
    	addcomment1.setToUserId(3383);
    	addcomment1.setToUserName("wesper");
    	addcomment1.setToUserType(1);
    	addcomment1.setCommentContent("dwtest");
    	addcomment1.setIPAddress("172.16.21.84");
    	addcomment1.setIsAnonymous(true);
    	
    	addcomment.setData(addcomment1);
    	
		addcomment.callService();
			Logger.comment("验证返回值");
			Logger.verifyEquals(500,new JSONObject(addcomment.getReturnData()).getInt("Status"), "响应报文-返回码");
		} catch(Exception e){
			   Logger.fail(e);
		   }
		
	}
	

}
